/**
 * 
 */
package com.cwnuzj.ffms.ui.view.navigation;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.cwnuzj.ffms.model.navigation.Category;
import com.cwnuzj.ffms.model.navigation.NavTreeData;


/**
 * @author Jeff Zheng
 *
 */
public class NavViewContentProvider implements IStructuredContentProvider, ITreeContentProvider {

	private NavTreeData model;

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		this.model = (NavTreeData) newInput;
	}

	@Override
	public Object[] getElements(Object inputElement) {
		return model.getCategories().toArray();
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		if (parentElement instanceof Category) {
			Category category = (Category) parentElement;
			return category.getNodes().toArray();
		}
		return null;
	}

	@Override
	public Object getParent(Object element) {
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {
		if (element instanceof Category) {
			return true;
		}
		return false;
	}
}
